import matplotlib.pyplot as plt
import numpy as np

# 创建数据
np.random.seed(42)
data1 = np.random.normal(100, 15, 1000)
data2 = np.random.normal(90, 20, 1000)

# 创建图表
fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(12, 5))

# 绘制直方图
ax1.hist(data1, bins=30, alpha=0.7, color='blue', edgecolor='black')
ax1.set_title('Histogram of Data 1')
ax1.set_xlabel('Value')
ax1.set_ylabel('Frequency')

ax2.hist(data2, bins=30, alpha=0.7, color='red', edgecolor='black')
ax2.set_title('Histogram of Data 2')
ax2.set_xlabel('Value')
ax2.set_ylabel('Frequency')

# 显示图表
plt.tight_layout()
plt.show()

# 创建重叠直方图
plt.figure(figsize=(10, 6))
plt.hist(data1, bins=30, alpha=0.5, label='Data 1', color='blue')
plt.hist(data2, bins=30, alpha=0.5, label='Data 2', color='red')
plt.title('Overlapping Histograms')
plt.xlabel('Value')
plt.ylabel('Frequency')
plt.legend()
plt.show()